import React, { Component } from 'react'
import qs from 'qs'
import { cateGoodsList } from '../request/cate'

export default class goodslist extends Component {
    state = {
        goodsList: []
    }
    UNSAFE_componentWillMount() {
        console.log(this.props.location.search)
        var get_params = qs.parse(this.props.location.search.substr(1))
        cateGoodsList(get_params.id).then(res => {
            if (res.code === 200) {
                this.setState({ goodsList: res.list })
            }
        })
    }
    render() {
        const { goodsList } = this.state
        return (
            <div>
                <div className="page-title">商品列表</div>
                {/* <!-- 商品列表 --> */}
                <div className="goodslist">
                    {
                        goodsList.map(item => {
                            return <div key={item.id} className="item">
                                <img src={this.$static_url+item.img} alt="" />
                                <div>
                                    <h5><a href={"/goodsdetail?id="+item.id}>{item.goodsname}</a></h5>
                                    <p className="price">&yen; {item.price}</p>
                                    <p className="market-price">&yen; {item.market_price}</p>
                                    <button className="btn-cart">加入购物车</button>
                                </div>
                            </div>
                        })
                    }


                </div>
            </div>
        )
    }
}
